#include "eventutil.h"

EventUtil::EventUtil() {}

QString EventUtil::getDrageOneFileName(QDragEnterEvent *event)
{
    auto mimedata = event->mimeData();

    QUrl url = mimedata->urls()[0];

    return url.toLocalFile();
}

QString EventUtil::getDropOneFileName(QDropEvent *event)
{
    auto mimedata = event->mimeData();

    QUrl url = mimedata->urls()[0];

    return url.toLocalFile();
}

bool EventUtil::isDrageOneFile(QDragEnterEvent *event)
{
    auto mimedata = event->mimeData();
    if (mimedata->hasUrls() == false) {
        return false;
    }

    QUrl url = mimedata->urls().first();
    if (url.isLocalFile() == false) {
        return false;
    }
    return true;
}

bool EventUtil::isDrageOneFileSuffix(QDragEnterEvent *event, QString suffix)
{
    if (isDrageOneFile(event) == false) {
        return false;
    }
    return getDrageOneFileName(event).endsWith(suffix);
}
